<?php


namespace app\common\service;


use think\Exception;

class delService
{
    public function delAll($data, $model)
    {
        if(is_array($data)){
            $bool = $this->checkID($data);
        } elseif(is_string($data)){
            $arr = json_decode($data, true);
            $bool = $this->checkID($arr);
        } else{
            $bool = false;
        }
        if($bool == true){
            $this->delData();
        }
    }

    /**
     * 校验每个value是否为数字
     * @param $arr
     * @return bool 是否整个数组的value都为数字
     */
    private function checkID($arr)
    {
        $bool = true;
        foreach ($arr as $value){
            if(is_numeric($value)){
                continue;
            }
            $bool = false;
            break;
        }
        return $bool;
    }

    private function delData($arr, $model)
    {
        try{
            $model->where('id', 'in', $arr)
                ->delete();
        }catch (\Exception $e){
            return false;
        }
        return true;
    }
}